/**
 * @file    app_main.c
 * @author  Azolla (1228449928@qq.com)
 * @brief   app mian func
 * @version 0.1
 * @date    2025-04-15
 *
 * @copyright Copyright (c) 2025
 * */
/******************************************************************************/
/* Inclue */
#include "debug.h"
 
#define TAG                  "app_main"
#define LOG_SET_LEVEL        LOG_LEVEL_INF
#include "hal_log.h"         /*!< Must be placed after LOG_SET_LEVEL >*/
void GPIO_Toggle_INIT(void)
{
    GPIO_InitTypeDef GPIO_InitStructure = {0};

    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_Init(GPIOA, &GPIO_InitStructure);
}

static void system_init(void)
{
    NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
    Delay_Init();
    USART_Printf_Init(115200);
    LOGI("SystemClk: %ldHz", SystemCoreClock);
    LOGI("ChipID: %08lx", DBGMCU_GetCHIPID() );
}

static void driver_init(void)
{
    GPIO_Toggle_INIT();
}

void hardfault_test(void) {
    printf("hardfault test\r\n");
    for (uint32_t i = 0; i < 16; i++) {
        printf("test:%08lX\r\n", *(uint32_t *)(0x500 + i));
    }
}
int main(void)
{
    system_init();

    driver_init();
 
    while (1) {
        static bool direct = true;
        GPIO_WriteBit(GPIOA, GPIO_Pin_0, direct); direct = !direct;
        Delay_Ms(1000); 
        LOGI("Main loop running...");
        static uint16_t conut = 0;
        if (++conut >= 5) {
            conut = 0;
            hardfault_test();
        }
    }
    return 0;
}
 